Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPLIB-1596 Fully describe $search, $searchMeta and $vectorSearch stages #1537

Merged
merged 3 commits into from
Dec 4, 2024

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Nov 25, 2024

Fix PHPLIB-1596

The parameters of the $search and $searchMeta stages are currently not described. Changing the generic property object into a full list of named arguments would be a breaking change after the first release of this code, so it's now or never.

For the tests, you can see the deep structure of options is not described. That's something we an do later.

@GromNaN GromNaN requested a review from a team as a code owner November 25, 2024 20:36
@GromNaN GromNaN requested a review from jmikola November 25, 2024 20:36
@GromNaN GromNaN changed the title PHPLIB-1596 Fully describe $search and $searchMeta stages PHPLIB-1596 Fully describe $search and $searchMeta stages Nov 25, 2024
@GromNaN GromNaN force-pushed the PHPLIB-1596 branch 4 times, most recently from e433932 to ba5c7b9 Compare November 26, 2024 18:14
@GromNaN GromNaN changed the title PHPLIB-1596 Fully describe $search and $searchMeta stages PHPLIB-1596 Fully describe $search, $searchMeta and $vectorSearch stages Nov 26, 2024
src/Builder/Encoder/OperatorEncoder.php Fixed Show fixed Hide fixed
src/Builder/Encoder/OperatorEncoder.php Fixed Show fixed Hide fixed
src/Builder/Stage/VectorSearchStage.php Dismissed Show dismissed Hide dismissed
Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking a first pass and will leave more feedback on other YAML files later.

generator/composer.json Show resolved Hide resolved
generator/src/OperatorTestGenerator.php Outdated Show resolved Hide resolved
generator/src/OperatorTestGenerator.php Show resolved Hide resolved
tests/Builder/Stage/VectorSearchStageTest.php Show resolved Hide resolved
tests/Builder/Search/Pipelines.php Show resolved Hide resolved
generator/config/search/exists.yaml Outdated Show resolved Hide resolved
generator/config/search/facet.yaml Outdated Show resolved Hide resolved
generator/config/search/geoShape.yaml Show resolved Hide resolved
generator/config/search/geoShape.yaml Outdated Show resolved Hide resolved
generator/config/search/geoWithin.yaml Outdated Show resolved Hide resolved
Copy link
Member Author

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this first review. I'll commit the fixes.

generator/config/search/autocomplete.yaml Outdated Show resolved Hide resolved
generator/config/expressions.php Show resolved Hide resolved
generator/config/search/embeddedDocument.yaml Outdated Show resolved Hide resolved
generator/config/search/equals.yaml Show resolved Hide resolved
generator/config/search/exists.yaml Outdated Show resolved Hide resolved
generator/src/OperatorTestGenerator.php Outdated Show resolved Hide resolved
generator/src/OperatorTestGenerator.php Show resolved Hide resolved
tests/Builder/Search/Pipelines.php Show resolved Hide resolved
tests/Builder/Stage/VectorSearchStageTest.php Show resolved Hide resolved
generator/composer.json Show resolved Hide resolved
@GromNaN GromNaN force-pushed the PHPLIB-1596 branch 3 times, most recently from 2ea8f3a to 64e79e4 Compare November 26, 2024 23:09
@@ -145,6 +147,8 @@ private function convertYamlTaggedValues(mixed $object): mixed
'bson_decimal128' => new Decimal128($value),
'bson_utcdatetime' => new UTCDateTime(is_numeric($value) ? $value : new DateTimeImmutable($value)),
'bson_binary' => new Binary(base64_decode($value)),
'bson_objectId' => new ObjectId($value),
'bson_uuid' => new Binary(hex2bin(str_replace('-', '', $value)), Binary::TYPE_UUID),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I was curious, I went back and compared the original code you had with pack('h*', ...). See below:

<?php

// Initialized project with: composer require ramsey/uuid
require 'vendor/autoload.php';

use Ramsey\Uuid\Uuid;
use MongoDB\BSON\Binary;

$uuid = Uuid::uuid4();
var_dump($uuid);

$bytes = $uuid->getBytes();
$str = $uuid->toString();

$bin = new Binary($bytes, Binary::TYPE_UUID);
var_dump(bin2hex($bin));

$bin2 = new Binary(hex2bin(str_replace('-','',$str)), Binary::TYPE_UUID);
var_dump($bin == $bin2);

$bin3 = new Binary(pack('h*', str_replace('-','',$str)), Binary::TYPE_UUID);
var_dump($bin == $bin3);

$bin4 = new Binary(pack('H*', str_replace('-','',$str)), Binary::TYPE_UUID);
var_dump($bin == $bin4);

Output:

$ php foo.php 
class Ramsey\Uuid\Lazy\LazyUuidFromString#4 (2) {
  private ?Ramsey\Uuid\UuidInterface $unwrapped =>
  NULL
  private string $uuid =>
  string(36) "3a6224c2-f648-4978-b510-610c04fbbcd6"
}
string(32) "3a6224c2f6484978b510610c04fbbcd6"
bool(true)
bool(false)
bool(true)

So it looks like h (hex string, low nibble first) wouldn't have worked, but H (high nibble first) would have. hex2bin() is totally fine, though, and easier to read.

src/Builder/Encoder/OperatorEncoder.php Outdated Show resolved Hide resolved
src/Builder/Encoder/OperatorEncoder.php Outdated Show resolved Hide resolved
generator/config/stage/search.yaml Outdated Show resolved Hide resolved

# The various example from the doc are variations of the "query" parameter
# this is not pertinent for testing the aggregation builder, unless we create
# a queryString builder.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not 😉

Copy link
Member Author

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's review #1540 before going further.

generator/config/expressions.php Show resolved Hide resolved
use MongoDB\Tests\Builder\PipelineTestCase;

/**
* Test in search
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, the search operators are not prefixed by the dollar sign 🤦.
I'll do a following PR to add quotes as this will impact all test classes (or maybe remove the comment).

src/Builder/Encoder/OperatorEncoder.php Outdated Show resolved Hide resolved
src/Builder/Encoder/OperatorEncoder.php Outdated Show resolved Hide resolved
src/Builder/Encoder/OperatorEncoder.php Fixed Show fixed Hide fixed
src/Builder/Encoder/OperatorEncoder.php Fixed Show fixed Hide fixed
src/Builder/Encoder/OperatorEncoder.php Fixed Show fixed Hide fixed
src/Builder/Encoder/OperatorEncoder.php Fixed Show fixed Hide fixed
src/Builder/Encoder/OperatorEncoder.php Fixed Show fixed Hide fixed
@GromNaN GromNaN force-pushed the PHPLIB-1596 branch 2 times, most recently from 9b22965 to 9fe3bd1 Compare December 3, 2024 19:11
generator/config/stage/search.yaml Outdated Show resolved Hide resolved
generator/config/stage/search.yaml Show resolved Hide resolved
generator/config/stage/searchMeta.yaml Show resolved Hide resolved
generator/config/stage/vectorSearch.yaml Show resolved Hide resolved
@GromNaN GromNaN enabled auto-merge (squash) December 4, 2024 10:02
@GromNaN GromNaN merged commit c386f6d into mongodb:v1.x Dec 4, 2024
31 checks passed
@GromNaN GromNaN deleted the PHPLIB-1596 branch December 4, 2024 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants